
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>二叉树的二叉链表实现 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="遍历二叉树和线索二叉树.html" />
    
    
    <link rel="prev" href="二叉树.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    数据结构（C语言版） 复习总结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1.html">
            
                <a href="../chapter1.html">
            
                    
                    第一章 绪论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter2/chapter2.html">
            
                <a href="../chapter2/chapter2.html">
            
                    
                    第二章 线性表
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter2/顺序表.html">
            
                <a href="../chapter2/顺序表.html">
            
                    
                    线性表的顺序表示和实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter2/链表.html">
            
                <a href="../chapter2/链表.html">
            
                    
                    线性表的链式表示和实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter3/chapter3.html">
            
                <a href="../chapter3/chapter3.html">
            
                    
                    第三章 栈和队列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter3/栈.html">
            
                <a href="../chapter3/栈.html">
            
                    
                    抽象数据类型栈的定义和实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter3/队列.html">
            
                <a href="../chapter3/队列.html">
            
                    
                    抽象数据类型队列的定义和实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    第四章 串
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter4/串类型.html">
            
                <a href="../chapter4/串类型.html">
            
                    
                    串类型的定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter4/串的表示和实现.html">
            
                <a href="../chapter4/串的表示和实现.html">
            
                    
                    串的表示和实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter4/串的模式匹配算法.html">
            
                <a href="../chapter4/串的模式匹配算法.html">
            
                    
                    串的模式匹配算法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    第五章 数组和广义表
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter5/数组的定义.html">
            
                <a href="../chapter5/数组的定义.html">
            
                    
                    数组的定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter5/矩阵的压缩存储.html">
            
                <a href="../chapter5/矩阵的压缩存储.html">
            
                    
                    矩阵的压缩存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter5/广义表.html">
            
                <a href="../chapter5/广义表.html">
            
                    
                    广义表
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    第六章 树和二叉树
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="树.html">
            
                <a href="树.html">
            
                    
                    树的定义与基本术语
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="二叉树.html">
            
                <a href="二叉树.html">
            
                    
                    二叉树
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.7.2.1" data-path="二叉树的二叉链表实现.html">
            
                <a href="二叉树的二叉链表实现.html">
            
                    
                    二叉树的二叉链表实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="遍历二叉树和线索二叉树.html">
            
                <a href="遍历二叉树和线索二叉树.html">
            
                    
                    遍历二叉树和线索二叉树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="树和森林.html">
            
                <a href="树和森林.html">
            
                    
                    树和森林
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="赫夫曼树.html">
            
                <a href="赫夫曼树.html">
            
                    
                    赫夫曼树
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <span>
            
                    
                    第七章 图
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter7/图.html">
            
                <a href="../chapter7/图.html">
            
                    
                    图的定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter7/图的存储结构.html">
            
                <a href="../chapter7/图的存储结构.html">
            
                    
                    图的存储结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter7/图的遍历.html">
            
                <a href="../chapter7/图的遍历.html">
            
                    
                    图的遍历
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../chapter7/最小生成树.html">
            
                <a href="../chapter7/最小生成树.html">
            
                    
                    最小生成树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../chapter7/有向无环图.html">
            
                <a href="../chapter7/有向无环图.html">
            
                    
                    有向无环图的应用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../chapter8/查找.html">
            
                <a href="../chapter8/查找.html">
            
                    
                    第八章 查找
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../chapter8/静态查找表.html">
            
                <a href="../chapter8/静态查找表.html">
            
                    
                    静态查找表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../chapter8/动态查找表.html">
            
                <a href="../chapter8/动态查找表.html">
            
                    
                    动态查找表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../chapter8/哈希表.html">
            
                <a href="../chapter8/哈希表.html">
            
                    
                    哈希表
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter9/内部排序.html">
            
                <a href="../chapter9/内部排序.html">
            
                    
                    第九章 内部排序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter9/插入排序.html">
            
                <a href="../chapter9/插入排序.html">
            
                    
                    插入排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter9/选择排序.html">
            
                <a href="../chapter9/选择排序.html">
            
                    
                    选择排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter9/快速排序.html">
            
                <a href="../chapter9/快速排序.html">
            
                    
                    快速排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter9/归并排序和基数排序.html">
            
                <a href="../chapter9/归并排序和基数排序.html">
            
                    
                    归并排序和基数排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter9/排序方法的比较.html">
            
                <a href="../chapter9/排序方法的比较.html">
            
                    
                    排序方法的比较
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >二叉树的二叉链表实现</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x4E8C;&#x53C9;&#x94FE;&#x8868;&#x5B9E;&#x73B0;">&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x4E8C;&#x53C9;&#x94FE;&#x8868;&#x5B9E;&#x73B0;</h2>
<p>&#x4E8C;&#x53C9;&#x6811;&#x4E00;&#x822C;&#x91C7;&#x7528;&#x4E8C;&#x53C9;&#x94FE;&#x8868;&#x5B58;&#x50A8;&#xFF0C;&#x57FA;&#x672C;&#x601D;&#x60F3;&#x662F;&#xFF1A;&#x4EE4;&#x4E8C;&#x53C9;&#x94FE;&#x8868;&#x4E2D;&#x6BCF;&#x4E2A;&#x7ED3;&#x70B9;&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;&#x94FE;&#x8868;&#x7ED3;&#x70B9;&#xFF0C;&#x7ED3;&#x70B9;&#x4E2D;&#x9664;&#x4E86;&#x5B58;&#x653E;&#x6570;&#x636E;&#x4FE1;&#x606F;&#x4E4B;&#x5916;&#xFF0C;&#x8FD8;&#x8BBE;&#x7F6E;&#x4E86;&#x6307;&#x5411;&#x5DE6;&#x3001;&#x53F3;&#x5B69;&#x5B50;&#x7684;&#x6307;&#x9488;&#x3002;&#x4F7F;&#x7528;&#x9012;&#x5F52;&#x8C03;&#x7528;&#x7684;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0;&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x5404;&#x9879;&#x57FA;&#x672C;&#x64CD;&#x4F5C;&#x3002;</p>
<blockquote>
<p>&#x8FD8;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x6307;&#x5411;&#x53CC;&#x4EB2;&#x7ED3;&#x70B9;&#x7684;&#x6307;&#x9488;&#xFF0C;&#x4FBF;&#x4E8E;&#x67E5;&#x627E;&#x53CC;&#x4EB2;&#x7ED3;&#x70B9;&#x3002;</p>
</blockquote>
<p><strong>&#x53C2;&#x6570;&#x8BF4;&#x660E;</strong></p>
<ul>
<li>BiNode&#x4E3A;&#x5B9A;&#x4E49;&#x7684;&#x4E8C;&#x53C9;&#x6811;&#x7ED3;&#x6784;&#x7C7B;&#x578B;</li>
<li>BiTree&#x4E3A;&#x4E8C;&#x53C9;&#x6811;&#x7C7B;&#x578B;&#x7684;&#x6307;&#x9488;</li>
<li>BiTreeSize&#x662F;&#x4E3A;&#x4E8C;&#x53C9;&#x6811;&#x7C7B;&#x578B;&#x5206;&#x914D;&#x7A7A;&#x95F4;</li>
</ul>
<pre><code class="lang-C"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;stdio.h&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;stdlib.h&gt;</span></span>

<span class="hljs-comment">/**
 * &#x4E8C;&#x53C9;&#x6811;&#x5B58;&#x50A8;&#x7ED3;&#x6784;&#x5B9A;&#x4E49;
 */</span>
<span class="hljs-keyword">typedef</span> <span class="hljs-keyword">struct</span> BiNode
{
    <span class="hljs-keyword">char</span> data;
    <span class="hljs-keyword">struct</span> BiNode *lchild;
    <span class="hljs-keyword">struct</span> BiNode *rchild;
}BiNode, *BiTree;

<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> BiTreeSize (BiTree)malloc(sizeof(BiNode)) <span class="hljs-comment">// &#x4E8C;&#x53C9;&#x6811;&#x5206;&#x914D;&#x7A7A;&#x95F4;&#x5B9A;&#x4E49;</span></span>

<span class="hljs-comment">/**
 * &#x4E8C;&#x53C9;&#x6811;&#x521D;&#x59CB;&#x5316;
 * &#x5C06;&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x5934;&#x6307;&#x9488;&#x7F6E;&#x4E3A;&#x7A7A;
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">InitBiTree</span><span class="hljs-params">(BiTree &amp;root)</span>
</span>{
    root = <span class="hljs-literal">NULL</span>;
}

<span class="hljs-comment">/**
 * &#x4E8C;&#x53C9;&#x6811;&#x5224;&#x7A7A;&#x64CD;&#x4F5C;
 * &#x5934;&#x6307;&#x9488;&#x4E3A;&#x7A7A;&#xFF0C;&#x8FD4;&#x56DE; 0&#xFF1B;&#x5426;&#x5219;&#x8FD4;&#x56DE; 1
 */</span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">BiTreeEmpty</span><span class="hljs-params">(BiTree root)</span>
</span>{
    <span class="hljs-keyword">if</span> (root == <span class="hljs-literal">NULL</span>)
    {
        <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
    }
    <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
}

<span class="hljs-comment">/**
 * &#x4F7F;&#x7528;&#x524D;&#x5E8F;&#x904D;&#x5386;&#x521B;&#x5EFA;&#x4E8C;&#x53C9;&#x6811;
 * &#x8F93;&#x5165;&#x524D;&#x5E8F;&#x5E8F;&#x5217;&#xFF0C;&#x4E3A;&#x5176;&#x5206;&#x914D;&#x50A8;&#x5B58;&#x7A7A;&#x95F4;&#xFF0C;&#x7136;&#x540E;&#x4F7F;&#x7528;&#x9012;&#x5F52;&#x8C03;&#x7528;&#x7684;&#x65B9;&#x5F0F;&#x521B;&#x5EFA;&#x5176;&#x5DE6;&#x3001;&#x53F3;&#x5B50;&#x6811;
 * &#x5F53;&#x5BF9;&#x5E94;&#x5B50;&#x6811;&#x4E3A;&#x7A7A;&#x65F6;&#x8F93;&#x5165;&#x7A7A;&#x683C;&#x5B57;&#x7B26;&#xFF0C;&#x4F7F;&#x5176;&#x6307;&#x5411;&#x4E3A;&#x7A7A;
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">CreatBiTree</span><span class="hljs-params">(BiTree &amp;root)</span>
</span>{
    <span class="hljs-keyword">char</span> ch;
    <span class="hljs-built_in">scanf</span>(<span class="hljs-string">&quot;%c&quot;</span>, &amp;ch);
    getchar();
    <span class="hljs-keyword">if</span> (ch == <span class="hljs-string">&apos; &apos;</span>) <span class="hljs-comment">// &#x7A7A;&#x683C;&#x8868;&#x793A;&#x7A7A;&#x7ED3;&#x70B9;</span>
    {
        root = <span class="hljs-literal">NULL</span>;
    }
    <span class="hljs-keyword">else</span>
    {
        root = BiTreeSize; <span class="hljs-comment">// &#x5206;&#x914D;&#x7A7A;&#x95F4; </span>
        root-&gt;data = ch;
        <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;&#x8BF7;&#x8F93;&#x5165;%c&#x7684;&#x5DE6;&#x5B50;&#x7ED3;&#x70B9;&#xFF1A;&quot;</span>, root-&gt;data);
        CreatBiTree(root-&gt;lchild);
        <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;&#x8BF7;&#x8F93;&#x5165;%c&#x7684;&#x53F3;&#x5B50;&#x7ED3;&#x70B9;&#xFF1A;&quot;</span>, root-&gt;data);
        CreatBiTree(root-&gt;rchild);
    }
}

<span class="hljs-comment">/**
 * &#x53F6;&#x5B50;&#x7684;&#x603B;&#x6570;
 * &#x82E5;&#x67D0;&#x7ED3;&#x70B9;&#x4E0D;&#x4E3A;&#x7A7A;&#xFF0C;&#x800C;&#x5B83;&#x7684;&#x5DE6;&#x53F3;&#x5B69;&#x5B50;&#x7ED3;&#x70B9;&#x90FD;&#x4E3A;&#x7A7A;&#x65F6;&#xFF0C;&#x8BA1;&#x6570;&#x5668;&#x52A0; 1
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">LeafNum</span><span class="hljs-params">(BiTree root, <span class="hljs-keyword">int</span> &amp;Leaf)</span>
</span>{
    <span class="hljs-keyword">if</span> (BiTreeEmpty(root) == <span class="hljs-number">1</span>)
    {
        <span class="hljs-keyword">if</span> (root-&gt;lchild == <span class="hljs-literal">NULL</span> &amp;&amp; root-&gt;rchild == <span class="hljs-literal">NULL</span>)
        {
            Leaf++;
        }
        LeafNum(root-&gt;lchild, Leaf);
        LeafNum(root-&gt;rchild, Leaf);
    }
}

<span class="hljs-comment">/**
 * &#x7ED3;&#x70B9;&#x7684;&#x603B;&#x6570;
 * &#x82E5;&#x67D0;&#x7ED3;&#x70B9;&#x4E0D;&#x4E3A;&#x7A7A;&#xFF0C;&#x4F7F;&#x8BA1;&#x6570;&#x5668;&#x52A0; 1
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">NodeNum</span><span class="hljs-params">(BiTree root, <span class="hljs-keyword">int</span> &amp;Node)</span>
</span>{
    <span class="hljs-keyword">if</span> (BiTreeEmpty(root) == <span class="hljs-number">1</span>)
    {
        Node++;
        NodeNum(root-&gt;lchild, Node);
        NodeNum(root-&gt;rchild, Node);
    }
}


<span class="hljs-comment">/**
 * &#x6811;&#x7684;&#x6DF1;&#x5EA6;
 * &#x82E5;&#x4E8C;&#x53C9;&#x6811;&#x4E3A;&#x7A7A;&#xFF0C;&#x5219;&#x5B83;&#x7684;&#x6DF1;&#x5EA6;&#x4E3A; 0&#xFF0C;&#x5426;&#x5219;&#x5B83;&#x7684;&#x6DF1;&#x5EA6;&#x7B49;&#x4E8E;&#x5DE6;&#x3001;&#x53F3;&#x5B50;&#x6811;&#x4E2D;&#x7684;&#x6700;&#x5927;&#x6DF1;&#x5EA6;&#x52A0; 1
 */</span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">BiTreeDepth</span><span class="hljs-params">(BiTree root)</span>
</span>{
    <span class="hljs-keyword">int</span> ldepth, rdepth;
    <span class="hljs-keyword">if</span>(BiTreeEmpty(root) == <span class="hljs-number">0</span>)
    {
        <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
    }
    <span class="hljs-keyword">else</span>
    {
        ldepth = BiTreeDepth(root-&gt;lchild);
        rdepth = BiTreeDepth(root-&gt;rchild);
        <span class="hljs-keyword">if</span>(ldepth &gt; rdepth)
        {
            <span class="hljs-keyword">return</span> ldepth + <span class="hljs-number">1</span>;
        }
        <span class="hljs-keyword">else</span>
        {
            <span class="hljs-keyword">return</span> rdepth+<span class="hljs-number">1</span>;    
        }
    }
}

<span class="hljs-comment">/**
 * &#x524D;&#x5E8F;&#x904D;&#x5386;&#x8F93;&#x51FA;
 * &#x9996;&#x5148;&#x904D;&#x5386;&#x6839;&#x8282;&#x70B9;&#xFF0C;&#x63A5;&#x7740;&#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811;&#xFF0C;&#x6700;&#x540E;&#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811;&#x3002; 
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">PreOrder</span><span class="hljs-params">(BiTree root)</span>
</span>{
    <span class="hljs-keyword">if</span> (BiTreeEmpty(root) == <span class="hljs-number">0</span>) <span class="hljs-comment">// &#x5224;&#x65AD;&#x4E8C;&#x53C9;&#x6811;&#x662F;&#x5426;&#x4E3A;&#x7A7A;</span>
    {
        <span class="hljs-keyword">return</span>; <span class="hljs-comment">// &#x4E8C;&#x53C9;&#x6811;&#x4E3A;&#x7A7A;&#xFF0C;&#x5219;&#x904D;&#x5386;&#x7ED3;&#x675F;</span>
    }
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;%c&quot;</span>, root-&gt;data); <span class="hljs-comment">// &#x8F93;&#x51FA;&#x6839;&#x8282;&#x70B9; </span>
    PreOrder(root-&gt;lchild);   <span class="hljs-comment">// &#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811; </span>
    PreOrder(root-&gt;rchild);   <span class="hljs-comment">// &#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811; </span>
}

<span class="hljs-comment">/**
 * &#x4E2D;&#x5E8F;&#x904D;&#x5386;&#x8F93;&#x51FA;
 * &#x9996;&#x5148;&#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811;&#xFF0C;&#x63A5;&#x7740;&#x904D;&#x5386;&#x6839;&#x8282;&#x70B9;&#xFF0C;&#x6700;&#x540E;&#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811;&#x3002; 
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">InOrder</span><span class="hljs-params">(BiTree root)</span>
</span>{
    <span class="hljs-keyword">if</span> (BiTreeEmpty(root) == <span class="hljs-number">0</span>) <span class="hljs-comment">// &#x5224;&#x65AD;&#x4E8C;&#x53C9;&#x6811;&#x662F;&#x5426;&#x4E3A;&#x7A7A;</span>
    {
        <span class="hljs-keyword">return</span>;
    }
    InOrder(root-&gt;lchild);    <span class="hljs-comment">// &#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811; </span>
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;%c&quot;</span>, root-&gt;data); <span class="hljs-comment">// &#x8F93;&#x51FA;&#x6839;&#x8282;&#x70B9; </span>
    InOrder(root-&gt;rchild);    <span class="hljs-comment">// &#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811; </span>
}

<span class="hljs-comment">/**
 * &#x540E;&#x5E8F;&#x904D;&#x5386;&#x8F93;&#x51FA;
 * &#x9996;&#x5148;&#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811;&#xFF0C;&#x63A5;&#x7740;&#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811;&#xFF0C;&#x6700;&#x540E;&#x904D;&#x5386;&#x6839;&#x8282;&#x70B9; 
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">PostOrder</span><span class="hljs-params">(BiTree root)</span>
</span>{
    <span class="hljs-keyword">if</span> (BiTreeEmpty(root) == <span class="hljs-number">0</span>) <span class="hljs-comment">// &#x5224;&#x65AD;&#x4E8C;&#x53C9;&#x6811;&#x662F;&#x5426;&#x4E3A;&#x7A7A;</span>
    {
        <span class="hljs-keyword">return</span>;
    } 
    PostOrder(root-&gt;lchild);  <span class="hljs-comment">// &#x904D;&#x5386;&#x5DE6;&#x5B50;&#x6811; </span>
    PostOrder(root-&gt;rchild);  <span class="hljs-comment">// &#x904D;&#x5386;&#x53F3;&#x5B50;&#x6811; </span>
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;%c&quot;</span>, root-&gt;data); <span class="hljs-comment">// &#x8F93;&#x51FA;&#x6839;&#x7ED3;&#x70B9; </span>
}

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
    BiTree T;
    <span class="hljs-keyword">int</span> Node = <span class="hljs-number">0</span>, Leaf = <span class="hljs-number">0</span>;
    T = BiTreeSize; <span class="hljs-comment">// &#x4E3A;&#x6839;&#x7ED3;&#x70B9;&#x5206;&#x914D;&#x7A7A;&#x95F4;</span>
    InitBiTree(T);
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;&#x8BF7;&#x8F93;&#x5165;&#x4E8C;&#x53C9;&#x6811;&#x7684;&#x6839;&#x7ED3;&#x70B9;&#xFF1A;&quot;</span>);
    CreatBiTree(T);
    LeafNum(T, Leaf);
    NodeNum(T, Node);
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;&#x7ED3;&#x70B9;&#x6570;%d&#xFF0C;&#x53F6;&#x5B50;&#x6570;%d&#xFF0C;&#x6811;&#x7684;&#x6DF1;&#x5EA6;%d\n&quot;</span>, Node, Leaf, BiTreeDepth(T));
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;\n&#x524D;&#x5E8F;&#x904D;&#x5386;&#xFF1A;&quot;</span>);
    PreOrder(T);
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;\n&quot;</span>);
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;&#x4E2D;&#x5E8F;&#x904D;&#x5386;&#xFF1A;&quot;</span>);
    InOrder(T);
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;\n&quot;</span>);
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;&#x540E;&#x5E8F;&#x904D;&#x5386;&#xFF1A;&quot;</span>);
    PostOrder(T);
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;\n&quot;</span>);
    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="二叉树.html" class="navigation navigation-prev " aria-label="Previous page: 二叉树">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="遍历二叉树和线索二叉树.html" class="navigation navigation-next " aria-label="Next page: 遍历二叉树和线索二叉树">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"二叉树的二叉链表实现","level":"1.7.2.1","depth":3,"next":{"title":"遍历二叉树和线索二叉树","level":"1.7.3","depth":2,"path":"chapter6/遍历二叉树和线索二叉树.md","ref":"chapter6/遍历二叉树和线索二叉树.md","articles":[]},"previous":{"title":"二叉树","level":"1.7.2","depth":2,"path":"chapter6/二叉树.md","ref":"chapter6/二叉树.md","articles":[{"title":"二叉树的二叉链表实现","level":"1.7.2.1","depth":3,"path":"chapter6/二叉树的二叉链表实现.md","ref":"chapter6/二叉树的二叉链表实现.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter6/二叉树的二叉链表实现.md","mtime":"2018-08-22T03:52:58.966Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-09-02T10:05:33.540Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

